import requests
#使用get方式发送请求
#在地址栏拼接参数www.xxx.com/?key1=value1&key2=value2
#{key1:value1}
#Requests除了这种方式，还有可以使用params传参
#response = request。get(url:"https://www.baidu.com/s?wd=python%22")
#data = {'wd':'java'}
#response = requests.get("https://www.baidu.com/s?wd=python%22")
#print(response.url)
#print(response.text)

#直接向百度发送请求，获取不到页面
#rep=requests.get("https://www.baidu.com")
#需要添加用户代理放进请求头，则可以正常得到响应
headers={
    "User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36 Edg/122.0.0.0"
}
rep = requests.get("https://www.baidu.com/s?wd=python%22",headers=headers)
print(rep.content.decode("utf-8"))